﻿using BDShop.DAL;
using BDShop.Entities;
using System;
using System.Collections.Generic;
using IsolationLevel = System.Transactions.IsolationLevel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BDShop.Business
{
    public class ProductCommentService
    {
        public static List<ProductComment> GetByUserID(int userID,long productID)
        {
            List<ProductComment> lstComment = new List<ProductComment>();
            using (var context = new BDShopEntities(IsolationLevel.ReadUncommitted))
            {
                lstComment = context.ProductComments.Where(c => c.CustomerID == userID && c.ProductID==productID && c.Status == (int)CommentStatus.Active).ToList();
            }

            return lstComment;
        }

        public static bool Insert(ProductComment comment)
        {
            try
            {
                using (var context = new BDShopEntities(IsolationLevel.ReadCommitted))
                {

                    context.ProductComments.Add(comment);
                    context.SaveChanges();

                    return true;

                }
            }
            catch (Exception)
            {
                return false;
            }

        }
    }
}
